home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1995 #5 & #6
/
Amiga Plus CD - 1995 - No. 5 and 6.iso
/
pd
/
netz
/
term
/
extras
/
source
/
term-source.lha
/
Colour.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-28
|
5KB
|
224 lines
/*
** Colour.c
**
** Colour table support code
**
** Copyright © 1990-1995 by Olaf `Olsen' Barthel
** All Rights Reserved
**
** :ts=4
*/
#include "termGlobal.h"
/* Colour96xColourTable(const ULONG *Source96,struct ColourTable *Table,WORD NumColours):
*
* Convert 96 bit precision colours for colour table.
*/
VOID __regargs
Colour96xColourTable(const ULONG *Source96,struct ColourTable *Table,WORD NumColours)
{
WORD i;
for(i = 0 ; i < NumColours ; i++)
{
Table -> Entry[i] . Red = *Source96++;
Table -> Entry[i] . Green = *Source96++;
Table -> Entry[i] . Blue = *Source96++;
}
}
/* Colour12xColourTable(const UWORD *Source12,struct ColourTable *Table,WORD NumColours):
*
* Convert 12 bit precision colours for colour table.
*/
VOID __regargs
Colour12xColourTable(const UWORD *Source12,struct ColourTable *Table,WORD NumColours)
{
Colour12x96(Source12,(ULONG *)Table -> Entry,NumColours);
}
/* ColourTablex96(const struct ColourTable *Table,ULONG *Dest96,WORD NumColours):
*
* Convert colour table into 96 bit precision colours.
*/
VOID __regargs
ColourTablex96(const struct ColourTable *Table,ULONG *Dest96,WORD NumColours)
{
WORD i;
for(i = 0 ; i < NumColours ; i++)
{
*Dest96++ = Table -> Entry[i] . Red;
*Dest96++ = Table -> Entry[i] . Green;
*Dest96++ = Table -> Entry[i] . Blue;
}
}
/* ColourTablex12(const struct ColourTable *Table,UWORD *Dest12,WORD NumColours):
*
* Convert colour table into 12 bit precision colours.
*/
VOID __regargs
ColourTablex12(const struct ColourTable *Table,UWORD *Dest12,WORD NumColours)
{
ULONG r,g,b;
WORD i;
for(i = 0 ; i < NumColours ; i++)
{
r = Table -> Entry[i] . Red >> 28;
g = Table -> Entry[i] . Green >> 28;
b = Table -> Entry[i] . Blue >> 28;
*Dest12++ = (r << 8) | (g << 4) | b;
}
}
/* Colour12x96(const UWORD *Source12,ULONG *Dest96,WORD NumColours):
*
* Convert 12 bit precision colours into 96 bit colours.
*/
VOID __regargs
Colour12x96(const UWORD *Source12,ULONG *Dest96,WORD NumColours)
{
ULONG r,g,b;
UWORD v;
do
{
v = *Source12++;
r = (v & 0xF00) >> 8;
g = (v & 0x0F0) >> 4;
b = (v & 0x00F);
*Dest96++ = SPREAD((r << 4) | r);
*Dest96++ = SPREAD((g << 4) | g);
*Dest96++ = SPREAD((b << 4) | b);
}
while(--NumColours);
}
/* Colour96x12(const UWORD *Source12,ULONG *Dest96,WORD NumColours):
*
* Convert 96 bit precision colours into 12 bit colours.
*/
VOID __regargs
Colour96x12(const ULONG *Source96,UWORD *Dest12,WORD NumColours)
{
ULONG r,g,b;
do
{
r = (*Source96++) >> 28;
g = (*Source96++) >> 28;
b = (*Source96++) >> 28;
*Dest12++ = (r << 8) | (g << 4) | b;
}
while(--NumColours);
}
/* DeleteColourTable(struct ColourTable *Table):
*
* Delete a colour table.
*/
VOID __regargs
DeleteColourTable(struct ColourTable *Table)
{
FreeVecPooled(Table);
}
/* CreateColourTable(WORD NumEntries,UWORD *Source12,ULONG *Source96):
*
* Create a colour table and fill it with given data.
*/
struct ColourTable * __regargs
CreateColourTable(WORD NumEntries,const UWORD *Source12,const ULONG *Source96)
{
ColourTable *Record;
if(Record = (ColourTable *)AllocVecPooled(sizeof(ColourTable) + NumEntries * sizeof(ColourEntry),MEMF_ANY | MEMF_CLEAR))
{
Record -> NumColours = NumEntries;
if(Source12)
Colour12x96(Source12,(ULONG *)Record -> Entry,NumEntries);
if(Source96)
{
WORD i;
for(i = 0 ; i < NumEntries ; i++)
{
Record -> Entry[i] . Red = *Source96++;
Record -> Entry[i] . Green = *Source96++;
Record -> Entry[i] . Blue = *Source96++;
}
}
}
return(Record);
}
/* LoadColours(struct ViewPort *VPort,const struct ColourTable *Table,const UWORD *Colour12,WORD NumColours):
*
* Load a colour table.
*/
VOID __regargs
LoadColourTable(struct ViewPort *VPort,const struct ColourTable *Table,const UWORD *Colour12,WORD NumColours)
{
if(GfxBase -> LibNode . lib_Version >= 39 && Table)
LoadRGB32(VPort,(ULONG *)Table);
else
{
if(Colour12)
LoadRGB4(VPort,(UWORD *)Colour12,NumColours);
}
}
/* SetColour12(struct ViewPort *VPort,WORD Number,UWORD r,UWORD g,UWORD b):
*
* Load a single colour entry in 12 bit colour precision.
*/
VOID __regargs
SetColour12(struct ViewPort *VPort,WORD Number,UWORD r,UWORD g,UWORD b)
{
SetRGB4(VPort,Number,r,g,b);
}
/* SetColour96(struct ViewPort *VPort,ULONG Number,ULONG r,ULONG g,ULONG b):
*
* Load a single colour entry in 96 bit colour precision.
*/
VOID __regargs
SetColour96(struct ViewPort *VPort,ULONG Number,ULONG r,ULONG g,ULONG b)
{
if(GfxBase -> LibNode . lib_Version >= 39)
{
ULONG Table[5];
Table[0] = (1L << 16) | Number;
Table[1] = r;
Table[2] = g;
Table[3] = b;
Table[4] = 0;
LoadRGB32(VPort,Table);
}
else
SetRGB4(VPort,Number,r >> 28,g >> 28,b >> 28);
}